import requests

from api.merchant.api_mer_order import MerchantOrder
from base.base_request import MerRequests
from base.base_url import MerCouponsUrl


class MerCoupons(MerRequests, MerCouponsUrl):

    def coupons_list(self):  # 优惠券列表
        params = {
            'page': '1',
            'limit': '20',
            'status': '',
            'name': '',
            'type': '',
            'useType': '',
            'temp': '1761825510',
        }
        return self.get(self.coupons_list.__name__, url=self.KEY_coupons_list, params=params)

    def coupons_add(self, name=None):  # 优惠券添加
        json_data = {
            'category': 1,
            'isFixedTime': False,
            'name': name,
            'money': 1,
            'minPrice': 0,
            'day': 1,
            'isTimeReceive': False,
            'productIds': '',
            'receiveType': 2,
            'isLimited': False,
            'useStartTime': '',
            'useEndTime': '',
            'receiveStartTime': '',
            'receiveEndTime': '',
            'sort': 1,
            'total': 0,
            'status': False,
            'checked': [],
        }
        return self.post(self.coupons_add.__name__, url=self.KEY_coupons_add, data=json_data)

    def coupons_update(self, id=None):  # 优惠券更新
        url = f'{self.KEY_coupons_update}/{id}'
        return self.post(self.coupons_update.__name__, url)

    def coupons_delete(self, id=None):  # 删除优惠券
        url = f'{self.KEY_coupons_delete}/{id}'
        return self.post(self.coupons_delete.__name__, url)

    def coupons_copy(self, name=None):  # 优惠券复制
        json_data = {
            'category': 1,
            'isFixedTime': False,
            'isTimeReceive': False,
            'name': name,
            'money': 1,
            'minPrice': 0,
            'day': 1,
            'receiveType': 2,
            'isLimited': False,
            'sort': 1,
            'total': 0,
            'status': True,
            'productIds': '',
            'checked': [],
            'useStartTime': '',
            'useEndTime': '',
            'receiveStartTime': '',
            'receiveEndTime': '',
        }

        return self.post(self.coupons_copy.__name__, url=self.KEY_coupons_copy, data=json_data)


if __name__ == '__main__':
    Coupons = MerCoupons()
    print(Coupons.coupons_list())
    print(Coupons.coupons_add())
    print(Coupons.coupons_update())
    print(Coupons.coupons_copy())
    print(Coupons.coupons_delete())

